package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.service.NursingProjectService;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    //分页查询
    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingProjectPageInfo);
    }

    //添加护理项目
    @PostMapping
    @ApiOperation("添加护理项目")
    public ResponseResult save(
            @ApiParam(value = "添加护理项目",required = true)
            @RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.save(nursingProjectDto);
        return ResponseResult.success();
    }

    //根据ID回显护理项目
    @GetMapping("/{id}")
    @ApiOperation("回显护理项目")
    public ResponseResult findById(@PathVariable("id")Long id){
        NursingProjectVo nursingProjectVo = nursingProjectService.findById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    //修改护理项目
    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return ResponseResult.success();
    }

    //删除护理项目
    @DeleteMapping("/{ids}")
    @ApiOperation("删除护理项目")
    public ResponseResult delete(@PathVariable("ids") List<Long> ids){
        nursingProjectService.delete(ids);
        return ResponseResult.success();
    }

    //修改护理项目的状态
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理项目的状态")
    public ResponseResult updateStatus(@ApiParam(value = "护理项目ID",required = true) @PathVariable("id") Long id,
                                       @ApiParam(value = "护理项目状态",required = true) @PathVariable("status")Integer status){
        nursingProjectService.updateStatus(id,status);
        return ResponseResult.success();
    }
}